/**
 * Created by zhangqingxi on 2017/3/21.
 */

$(function () {

    //表单提交
    $('#btn_save').on('click',function () {
        var index=layer.confirm('是否确定保存？', {
            btn: ['确定','取消'] //按钮
        }, function(){

            $('#form_user').form('submit', {
                url: ROOT_PATH+'/permission/user/updatePassword.shtml',
                onSubmit: function (param) {
                    var isValid = $(this).form('validate');
                    if (!isValid) {
                        layer.close(index);
                        layer.msg("请正确填写表单")
                    }

                    return $(this).form('validate');
                },
                success: function (result) {
                    var data = $.parseJSON(result);

                    if(data.success){
                        window.parent.closeLayer(data);
                    }else{
                        $('#password').textbox('reset');
                        $('#newPassword').textbox('reset');
                        $('#againPassword').textbox('reset');
                        layer.msg(data.message,{time:3000,icon:2});
                    }
                    //layer.close(index);

                }
            });
        });

    });

    //再次输入密码的验证
    $.extend($.fn.validatebox.defaults.rules,{

        equals:{
            validator:function(value,param){
                var flag=value==$(param[0]).val();

                if(!flag){
                    $('#pwd_err').css('display','block');
                }else{
                    $('#pwd_err').css('display','none');
                }
                return flag;
            },
            message:'两次输入的密码不相同'
        }
    });




});